﻿namespace Anley.DomainDrivenDesign.Contract.Extension;

/// <summary>
/// 检查扩展类
/// </summary>
public static class CheckExtension
{
    /// <summary>
    /// 非空字符串
    /// </summary>
    /// <param name="value">参数值</param>
    /// <param name="name">参数名</param>
    public static string NotWhiteSpace(this string value, string name)
    {
        if (string.IsNullOrWhiteSpace(value))
            throw new ArgumentNullException(name);
        return value;
    }

    /// <summary>
    /// 非空字符串
    /// </summary>
    /// <param name="value">参数值</param>
    /// <param name="name">参数名</param>
    public static string NotNullOrWhiteSpace(this string? value, string name)
    {
        if (string.IsNullOrWhiteSpace(value))
            throw new ArgumentNullException(name);
        return value;
    }

    /// <summary>
    /// 非空对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="value"></param>
    /// <param name="name"></param>
    public static T NotNull<T>(this T? value, string name)
        where T : class
    {
        if (value == null)
            throw new ArgumentNullException(name);
        return value;
    }
}